home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FSCANF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  615 b   |  28 lines

  1. /*  fscanf.c, from p.432 of Turbo C Bible  */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     int i;
  6.     FILE *infile;
  7.     char token[80];
  8.                 /*  Open the file. Note that we need two  */
  9.                 /*  '\'                                   */
  10.     if ((infile = fopen("c:\\autoexec.bat", "r")) == NULL)
  11.     {
  12.     perror("fopen failed");
  13.     exit(1);
  14.     }
  15.     printf("First 10 blank separated strings in  c:\\autoexec.bat:\n");
  16.     for(i = 0; i < 10; i++)
  17.     {
  18.     if(fscanf(infile, " %s", token) == EOF)
  19.     {
  20.         printf("File ended!\n");
  21.         break;
  22.     }
  23.     else
  24.     {
  25.         printf("Token %d = \"%s\"\n", i, token);
  26.     }
  27.     }
  28. }